<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="报工人" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入报工人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作站名称" prop="workstationName">
        <el-input
          v-model="queryParams.workstationName"
          placeholder="请输入工作站名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报工日期" prop="feedbackTimes">
        <el-date-picker
          clearable
          v-model="feedbackTimes"
          type="datetimerange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="工单编号" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入工单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单名称" prop="workorderName">
        <el-input
          v-model="queryParams.workorderName"
          placeholder="请输入工单名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务编号" prop="taskCode">
        <el-input
          v-model="queryParams.taskCode"
          placeholder="请输入任务编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务名称" prop="taskName">
        <el-input
          v-model="queryParams.taskName"
          placeholder="请输入任务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="产品物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入产品物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-search" size="mini" @click="handleAllQuery">查询所有</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="feedbackList">
      <el-table-column
        label="工作站"
        width="120px"
        align="center"
        prop="workstationName"
        :show-overflow-tooltip="true"/>
      <el-table-column
        label="生产工单编号"
        width="150px"
        align="center"
        prop="workorderCode"
        :show-overflow-tooltip="true"/>
      <el-table-column label="任务编号" width="120px" align="center" prop="taskCode" :show-overflow-tooltip="true"/>
      <el-table-column
        label="任务名称"
        width="180px"
        align="center"
        prop="taskName"
        :show-overflow-tooltip="true"/>
      />
      <el-table-column
        label="产品物料编码"
        width="120px"
        align="center"
        prop="itemCode"
        :show-overflow-tooltip="true"/>
      <el-table-column
        label="产品物料名称"
        width="150px"
        align="center"
        prop="itemName"
        :show-overflow-tooltip="true"/>
      <el-table-column label="规格型号" align="center" prop="specification"/>
      <el-table-column
        label="报工数量"
        align="center"
        prop="quantityFeedback">
        <template slot-scope="scope">
          <el-tag type="success">{{ scope.row.quantityFeedback }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="合格品数量"
        width="100px"
        align="center"
        prop="quantityQualified">
        <template slot-scope="scope">
          <el-tag type="primary">{{ scope.row.quantityQualified }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="不良品数量"
        width="100px"
        align="center"
        prop="quantityUnquanlified">
        <template slot-scope="scope">
          <el-tag type="danger">{{ scope.row.quantityUnquanlified }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="报工人" align="center" prop="nickName">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.nickName }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="报工时间"
        align="center"
        prop="feedbackTime"
        width="150"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.feedbackTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getListFeedback } from "@/api/mes/pro/feedback";

export default {
  name: 'feedback',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产计划表格数据
      feedbackList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      feedbackTimes: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName: null,
        workstationName: null,
        workorderCode: null,
        workorderName: null,
        taskCode: null,
        taskName: null,
        itemCode: null,
        itemName: null,
        beginTime: null,
        endTime: null
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询生产计划列表 */
    getList() {
      this.loading = true;
      this.queryParams.beginTime = null;
      this.queryParams.endTime = null;
      if (this.feedbackTimes) {
        this.queryParams.beginTime = this.feedbackTimes[ 0 ];
        this.queryParams.endTime = this.feedbackTimes[ 1 ];
      }
      getListFeedback(this.queryParams).then(response => {
        this.feedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        planId: null,
        planCode: null,
        planName: null,
        orderSource: null,
        sourceCode: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpc: null,
        unitOfMeasure: null,
        quantity: null,
        itemOrProduct: null,
        startDate: null,
        endDate: null,
        requestDate: null,
        status: 'PREPARE',
        remark: null
      };
      this.autoGenFlag = false;
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleAllQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 1000000;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        '/mes/pro/feedback/feedbackDownload',
        {
          ...this.queryParams
        },
        `feedback_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
